const puppeteer = require('puppeteer');
const fs = require('fs');
const path = require('path');
const TaskRunner = require('./TaskRunner');
const { runCommond } = require('./runCommond');

puppeteer
    .launch({
        headless: false,
    })
    .then(async (browser) => {
        const code = fs.readFileSync(path.resolve(__dirname, './scripts/1.json'));
        const tasks = JSON.parse(code);

        const runner = new TaskRunner({
            tasks,
            index: 0,
            runTask: (...args) => {
                return runCommond(browser, ...args);
            },
            onStart: () => {
                console.log(`Task start`);
            },
            onPause: () => {
                console.log(`Task pause`);
            },
            onResume: () => {
                console.log(`Task resume`);
            },
            onStop: () => {
                console.log(`Task stop`);
            },
            onRetry: () => {
                console.log(`Task retry`);
            },
            onTaskComplete: (index) => {
                console.log(`Task ${index} completed`);
            },
            onError: (error) => {
                console.error('Execution error:', error);
            }
        });
        runner.start();
        setTimeout(() => {
            runner.pause()
        }, 500)
        // setTimeout(() => {
        //     runner.resume()
        // }, 5000)
    });
